package sun.superstring;

public class ArrayDemo1 {
    public static void main(String[] args) {
        // 目标：认识、使用数组的好处，数组的定义和使用
        randomName();
    }

    // 我是一名Java的初学者，请帮我开发一个随机点名的方法，假设有15个学生
    public static void randomName() {
        // 1. 定义一个数组，用来存储15个学生的姓名
        // 静态初始化一个数组：定义数组的时候，数据已经确定好了
//      String[] names = {"张三","李四","王五","赵六","孙七","周八","吴九","钱十","唐十一","冯十二","陈十三","楚十四","魏十五","江十六","朱十七"};
//      String[] names = new String[] {"张三","李四","王五","赵六","孙七","周八","吴九","钱十","唐十一","冯十二","陈十三","楚十四","魏十五","江十六","朱十七"};
        String names [] = new String[] {"张三","李四","王五","赵六","孙七","周八","吴九","钱十","唐十一","冯十二","陈十三","楚十四","魏十五","江十六","朱十七"};
        //                          索引   0     1     2     3     4     5     6     7      8         9     10    11    12    13    14    15
        // String [] 定义一个字符串类型的数组，names是数组的名字


        // 2. 随机获取一个索引值
        // Math.random()  :   [0 - 1)
        // names.length : 是数组长度，即元素个数 15
        // Math.random() * names.length : [0 - 15)   =====>    [0, 14]
        int index = (int)(Math.random() * names.length);
        // 3. 打印数组中的元素
        System.out.println("总共有" + names.length +"个学生，随机抽一个同学是：" + names[index]);
        System.out.println(names);
    }

}
